/*
 * Copyright (C) 2018 Logos Technology Ltd.
 */

package com.logos.common.permissions;

import android.content.Context;
import android.content.pm.PackageManager;
import android.util.Log;

import androidx.core.content.ContextCompat;

public class PermissionsChecker {
    private static final String TAG = "PermissionsChecker";
    private final Context mContext;

    public PermissionsChecker(Context context) {
        mContext = context.getApplicationContext();
    }

    /**
     * 判断权限集合
     *
     * @param permissions 权限集合
     * @return 是否缺少权限.
     */
    public boolean lacksPermissions(String... permissions) {
        for (String permission : permissions) {
            if (lacksPermission(permission)) {
                return true;
            }
            Log.d(TAG, "lacksPermissions: " + permissions);
        }
        return false;
    }

    // 判断是否缺少权限
    private boolean lacksPermission(String permission) {
        return ContextCompat.checkSelfPermission(mContext, permission)
                == PackageManager.PERMISSION_DENIED;
    }
}
